package com.lin.androidgame21;

import android.graphics.Bitmap;

/***

 *Create By LWL Write

 **/
public class Player extends Sprite {

    private Dir dir;
    private int[] leftFrameSequence;
    private int[] rightFrameSequence;
    private int[] upFrameSequence;
    private int[] downFrameSequence;

    Player(Bitmap bitmap, int width, int height) {
        super(bitmap, width, height);
    }

    public Dir getDir() {
        return dir;
    }

    public void setDir(Dir dir) {
        this.dir = dir;
    }

    public int[] getLeftFrameSequence() {
        return leftFrameSequence;
    }

    public void setLeftFrameSequence(int[] leftFrameSequence) {
        this.leftFrameSequence = leftFrameSequence;
    }

    public int[] getRightFrameSequence() {
        return rightFrameSequence;
    }

    public void setRightFrameSequence(int[] rightFrameSequence) {
        this.rightFrameSequence = rightFrameSequence;
    }

    public int[] getUpFrameSequence() {
        return upFrameSequence;
    }

    public void setUpFrameSequence(int[] upFrameSequence) {
        this.upFrameSequence = upFrameSequence;
    }

    public int[] getDownFrameSequence() {
        return downFrameSequence;
    }

    public void setDownFrameSequence(int[] downFrameSequence) {
        this.downFrameSequence = downFrameSequence;
    }

    @Override
    public void outOfBounds() {
        if (getX() < 0) {
            setX(0);
        } else if (getX() > 1280 - getWidth()) {
            setX(1280 - getWidth());
        }
        if (getY() < 0) {
            setY(0);
        } else if (getY() > 768 - getHeight()) {
            setY(768 - getHeight());
        }
    }

    public boolean footCollisionWith(MyMap myMap, int distanceX, int distanceY) {
        int footX = getX() + getWidth() / 2 + distanceX;
        int footY = getY() + getHeight() - 16 + distanceY;
        int footMapX = footX - myMap.getX();
        int footMapY = footY - myMap.getY();
        int footCol = footMapX / myMap.getWidth();
        int footRow = footMapY / myMap.getHeight();
        if (footCol >= myMap.getCols() || footRow >= myMap.getRows()) {
            return true;
        }
        if (myMap.getTiledCellIndex(footRow, footCol) != 0) {
            return true;
        }
        return false;
    }
}
